import React from "react"

class HelloWorld extends React.Component {
    constructor() {
        super()
        this.state = {
            message: "Hello World",
        }
    }

    changeText(){
        this.setState({
            message:"World Hello"
        })
    }

    render() {
        const { message } = this.state
        return (
            <div>
                <h2>{ message }</h2>
                <p>{ message }是程序员的第一个代码！</p>
                <button onClick={e=>this.changeText()}>改变文本</button>
            </div>
        )
    }

    componentDidMount(){
        console.log("HelloWorld componentDidMount")
    }
    // 组件的DOM被更新完成
    componentDidUpdate(){
        console.log("HelloWorld componentDidUpdate")
    }
    // 组件从DOM中卸载
    componentWillUnmount(){
        console.log("HelloWorld willUnmount")
    }
    
}

export default HelloWorld
